from rest_framework import exceptions
from rest_framework.views import exception_handler


def my_exception_handler1(exc, context):
    '''
    :param exc: 异常信息
    :param context: 上下文
    :return:
    '''
    # print("+++++++++++++++++++++++++++++++++++进入我的exception了++++++++++++++++++")
    error_response = exception_handler(exc=exc, context=context)
    if error_response:  # 属于APIException
        if isinstance(exc, exceptions.APIException):
            error_msg = exc.detail
        else:
            error_msg = str(exc)  # Http404 或者 PermissionDenied

        error_response.data = {
            'msg': 'error',
            'retcode': error_response.status_code,
            'error': error_msg
        }
        return error_response
